| Conditions | 9 |
| Paths | 48 |
| Total Lines | 87 |
| Lines | 86 |
| Ratio | 98.85 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 40 | objects.on('expand.drawer', function expand(event, speed, stay) { |
||
| 41 | View Code Duplication | var drawer = $(this), |
|
|
|
|||
| 42 | position = drawer.data('position'), |
||
| 43 | buttons = $('.button.drawer'), |
||
| 44 | button = buttons.filter('[href="#' + drawer.attr('id') + '"]'), |
||
| 45 | samePositionButtons = buttons.filter('.' + position), |
||
| 46 | context = drawer.data('context') ? '.' + drawer.data('context') : '', |
||
| 47 | height = getHeight(); |
||
| 48 | |||
| 49 | drawer.trigger('expandstart.drawer'); |
||
| 50 | |||
| 51 | speed = (typeof speed === 'undefined' ? settings.speed : speed); |
||
| 52 | stay = (typeof stay === 'undefined' ? false : true); |
||
| 53 | |||
| 54 | // update button state |
||
| 55 | samePositionButtons.removeClass('selected'); |
||
| 56 | |||
| 57 | // Close opened drawers from same region |
||
| 58 | $('.drawer.' + position).filter(function(index) { |
||
| 59 | return $(this).data('open'); |
||
| 60 | }).trigger('collapse.drawer', [speed, true]); |
||
| 61 | |||
| 62 | if (position === 'vertical-left') { |
||
| 63 | drawer.css({ |
||
| 64 | width: 0, |
||
| 65 | height: height, |
||
| 66 | display: 'block' |
||
| 67 | }) |
||
| 68 | .animate({ |
||
| 69 | width: settings.verticalWidth |
||
| 70 | }, { |
||
| 71 | duration: speed, |
||
| 72 | step: function(now, fx){ |
||
| 73 | form.css('margin-left', now + 1); // +1px right border |
||
| 74 | }, |
||
| 75 | complete: function() { |
||
| 76 | form.css('margin-left', settings.verticalWidth + 1); // +1px right border |
||
| 77 | drawer.trigger('expandstop.drawer'); |
||
| 78 | } |
||
| 79 | }); |
||
| 80 | } |
||
| 81 | else if (position === 'vertical-right') { |
||
| 82 | drawer.css({ |
||
| 83 | width: 0, |
||
| 84 | height: height, |
||
| 85 | display: 'block' |
||
| 86 | }) |
||
| 87 | .animate({ |
||
| 88 | width: settings.verticalWidth |
||
| 89 | }, { |
||
| 90 | duration: speed, |
||
| 91 | step: function(now, fx){ |
||
| 92 | form.css('margin-right', now + 1); // +1px left border |
||
| 93 | }, |
||
| 94 | complete: function() { |
||
| 95 | form.css('margin-right', settings.verticalWidth + 1); // +1px right border |
||
| 96 | drawer.trigger('expandstop.drawer'); |
||
| 97 | } |
||
| 98 | }); |
||
| 99 | } |
||
| 100 | else if (position === 'horizontal') { |
||
| 101 | drawer.animate({ |
||
| 102 | height: 'show' |
||
| 103 | }, { |
||
| 104 | duration: speed, |
||
| 105 | complete: function() { |
||
| 106 | drawer.trigger('expandstop.drawer'); |
||
| 107 | } |
||
| 108 | }); |
||
| 109 | } |
||
| 110 | |||
| 111 | button.addClass('selected'); |
||
| 112 | |||
| 113 | // store state |
||
| 114 | if(Symphony.Support.localStorage === true) { |
||
| 115 | // Put in a try/catch incase we exceed storage space |
||
| 116 | try { |
||
| 117 | window.localStorage['symphony.drawer.' + drawer.attr('id') + context] = 'opened'; |
||
| 118 | } |
||
| 119 | catch(e) { |
||
| 120 | window.onerror(e.message); |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 124 | wrapper.addClass('drawer-' + position); |
||
| 125 | drawer.data('open', true); |
||
| 126 | }); |
||
| 127 | |||
| 264 |